/*生成环境配置文件：不需要一些dev-tools,dev-server和jshint校验等。和开发有关的东西删掉*/
var webpack = require('webpack');
var path = require('path');
var node_modules = path.resolve(__dirname, 'node_modules');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
// 该插件是对“webpack-md5-hash”的改进：在主文件中获取到各异步模块的hash值，然后将这些hash值与主文件的代码内容一同作为计算hash的参数，这样就能保证主文件的hash值会跟随异步模块的修改而修改。
var WebpackSplitHash = require('webpack-split-hash');
var url = require('url-loader');

var config = {
    entry:{
        portal: [
            "./static/skins/lightblue/assets/bootstrap/global/plugins/font-awesome/css/font-awesome.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/simple-line-icons/css/simple-line-icons.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap/css/bootstrap.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/uniform/css/uniform.default.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker3.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-select/bootstrap-select.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/select2/select2.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-table/bootstrap-table.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-sweetalert/sweetalert.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-toastr/toastr.min.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/bootstrap-pagination/bootstrap-pagination.css",
            "./static/skins/lightblue/assets/bootstrap/global/css/components-md.css",
            "./static/skins/lightblue/assets/bootstrap/global/css/plugins-md.css",
            "./static/skins/lightblue/assets/bootstrap/admin/layout2/css/layout.css",
            "./static/skins/lightblue/assets/bootstrap/admin/layout2/css/themes/grey.css",
            "./static/skins/lightblue/assets/bootstrap/admin/layout2/css/custom.css",
            "./static/skins/lightblue/assets/bootstrap/admin/pages/css/todo.css",
            "./static/skins/lightblue/assets/bootstrap/global/plugins/jstree/themes/default/style.min.css",
            "./static/skins/lightblue/assets/jquery-ui/jquery-ui.css"
        ]
    },
    output:{
        path:__dirname+'/static/skins/lightblue/assetsmin/platform/portal/',
        //以文件内容的MD5生成Hash名称的script来防止缓存
        filename: '[name].all.css'
    },
    module:{
        loaders:[{
                test:/\.css$/,
                //loader: 'style-loader!css-loader!url-loader'
                loader:["style-loader", "css-loader?minimize",'postcss-loader','less-loader',"url-loader"]
                //loader: ExtractTextPlugin.extract({ fallback: 'style', use: 'css' })
            },
            {
                test:/\.scss$/,
                loader:'style!css!sass'
            },
            //url-loader:图片、字体图标加载器，是对file-loader的上层封装,支持base64编码。传入的size（也有的写limit) 参数是告诉它图片如果不大于 25KB 的话要自动在它从属的 css 文件中转成 BASE64 字符串。
            {
                test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
                loader: 'url?&name=[name].[ext]'
            },
            {
                test: /\.((woff2?|svg)(\?v=[0-9]\.[0-9]\.[0-9]))|(woff2?|svg|jpe?g|png|gif|ico)$/,
                loaders: [
                    //小于10KB的图片会自动转成dataUrl，
                    'url?limit=10000&name=img/[hash:8].[name].[ext]',
                    'image?{bypassOnDebug:true, progressive:true,optimizationLevel:3,pngquant:{quality:"65-80",speed:4}}'
                ]
            },
            {
                test: /\.((ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9]))|(ttf|eot)$/,
                loader: 'url?limit=10000&name=[name].[ext]'
            }]
    },
    plugins:[
        //提取公共代码的插件，用于提取多个入口文件的公共脚本部分，然后生成一个vendors.js。注意HTML代码中要加载这个公共文件
        /*new webpack.optimize.CommonsChunkPlugin({
            name: 'vendors',
            filename: 'js/vendors.js'
        }),*/
        //在文件开头插入banner
        new webpack.BannerPlugin("The file is creted by Johnny. --"+ new Date()),
        //压缩js文件
        /*插件：单独使用style标签加载css文件.contenthash代表的是文本文件内容的hash值，也就是只有style文件的hash值*/
        new ExtractTextPlugin("css/[name].[contenthash:8].css"),//设置其路径(路径相对于path)
        /*插件：动态生成html，在webpack完成前端资源打包以后，自动将打包后的资源路径和版本号写入HTML中，达到自动化的效果。*/
        /*作用：生成具有独立hash值的css和js文件，即css和js文件hash值解耦.
         *缺点：webpack-md5-hash插件对chunk-hash钩子进行捕获并重新计算chunkhash，它的计算方法是只计算模块本身的当前内容（包括同步模块）。这种计算方式把异步模块的内容忽略掉了，会造成一个问题：异步模块的修改并未影响主文件的hash值。
         */
        //new WebpackMd5Hash()
    ]
}
module.exports = config;